package org.example.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.example.entity.system.Role;
import org.example.mapper.RoleMapper;
import org.example.service.RoleService;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author 魏锴
 * @description 针对表【tb_sys_role】的数据库操作Service实现
 * @createDate 2024-01-11 15:16:59
 */
@Service
public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role>
        implements RoleService {

    @Override
    public boolean insertRole(Role role) {
        return baseMapper.insertRole(role);
    }

    @Override
    public boolean updateRole(Role role) {
        return baseMapper.updateRole(role);
    }

    @Override
    public boolean deleteRole(int id) {
        return baseMapper.deleteRole(id);
    }

    @Override
    public List<Role> getRoleList() {
        return baseMapper.getRoleList();
    }

    @Override
    public List<Integer> getRoleIdList() {
        return baseMapper.getRoleIdList();
    }

    @Override
    public List<Integer> getRolesByUser(int user_id) {
        return baseMapper.getRolesByUser(user_id);
    }

    @Override
    public Role getRoleById(int role_id) {
        return baseMapper.getRoleById(role_id);
    }

    @Override
    public Role getRoleByIdWithPerm(int role_id) {
        return baseMapper.getRoleByIdWithPerm(role_id);
    }
    @Override
    public Map<String, String> getRoleIdMap() {
        List<Map<String,Object>> data = baseMapper.getRoleIdMap();
        Map<String,String> result = new HashMap<>();
        for (Map<String,Object> map:data)
            result.put(String.valueOf(map.get("id")), (String) map.get("name"));
        return result;
    }

    @Override
    public boolean grantRole(int user_id, int role_id) {
        return baseMapper.grantRole(user_id, role_id);
    }

    @Override
    public boolean revokeRole(int user_id, int role_id) {
        return baseMapper.revokeRole(user_id, role_id);
    }
}




